package com.flkin.modules.system.repository;

import com.flkin.modules.system.domain.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.Set;

/**
 * @author yanxiang.huang 2020-12-07 22:31:34
 */
public interface RoleRepository extends JpaRepository<Role, Long>, JpaSpecificationExecutor<Role> {

    @Query(value = "SELECT r.* " +
            "FROM `role` r, `user_role` ur " +
            "WHERE r.id = ur.role_id AND ur.user_id = ?1"
            , nativeQuery = true)
    Set<Role> findByUserId(Long id);
}
